<?php  
namespace app\common\components;
/**
* 
*/
class HttpCurl 
{
	
	//参数1：访问的URL，参数2：post数据(不填则为GET)，参数3：提交的$cookies,参数4：是否返回$cookies
 	public static function get($url){
        //初始化
	    $curl = curl_init();
	    //设置抓取的url
	    curl_setopt($curl, CURLOPT_URL, $url);
	   
	    //设置获取的信息以文件流的形式返回，而不是直接输出。
	    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
	    //设置为https访问
	    curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
	    curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
	    //执行命令
	    $res = curl_exec($curl);
	    //关闭URL请求
	    curl_close($curl);
	    //显示获得的数据
	    return $res;
	}
	public static function post($url,$data){
	    $curl = curl_init(); 
	    // echo $url;
	    // print_r(json_decode($data)) ;
	    //设置为https访问
	    curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
	    curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
	    
	    curl_setopt($curl, CURLOPT_URL, $url); 
	    curl_setopt($curl, CURLOPT_POST, 1);
	    curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);
	     curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length:' . strlen($data)));
   		curl_setopt($curl, CURLOPT_POSTFIELDS , $data);
    	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);  
	    $output = curl_exec($curl); 
	    curl_close($curl); 
	    return $output;     
	}
}
?>